package com.mini.demos.webgame.db;

import java.sql.Connection;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSourceFactory;

/**
 * dbcp连接池的用法
 */
public class DBPoolUtils {

	private static Properties properties;
	

	private static DataSource dataSource;

	private static Connection conn;

	static {
		try {
			properties = new Properties();

			// 载入dbcp的配置文件

			properties.load(DBPoolUtils.class.getResourceAsStream("/conf.properties"));

			// 创建个BasicDataSourceFactory对象用于创建连接池对象

			BasicDataSourceFactory b = new BasicDataSourceFactory();

			// 把properties对象设置给BasicDataSourceFactory

			dataSource = b.createDataSource(properties);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static DataSource getdataSource() {
		return dataSource;
	}

}
